package week08;

import java.util.Scanner;

class ArrayUtils{
	public static double findMax(double[] arr,int begin, int end) throws IllegalArgumentException{
		if(begin>=end){
			throw new IllegalArgumentException("begin:"+begin+" >= end:"+end);
		}
		if(begin<0){
			throw new IllegalArgumentException("begin:"+begin+" < 0");
		}
		if(end>arr.length){
			throw new IllegalArgumentException("end:"+end+" > arr.length");
		}
		double max=-1;
			for(int i=begin;i<=end-1;i++){
				if(arr[i]>max){
					max=arr[i];
				}
		}
		return max;	
		
	}
}

public class Main5 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in 

);
		int n=sc.nextInt();
		double[] arr=new double[n];
		for(int i=0;i<n;i++){
			int num=sc.nextInt();
			arr[i]=num;
		}
		while(sc.hasNextInt()){

				 try{
					 int begin=sc.nextInt();
					 int end=sc.nextInt();
				 double max=ArrayUtils.findMax(arr, begin, end);
				 System.out.println(max);
			} catch (Exception e) {
				System.out.println(e);
			}
				
				 
		}
		 try {
		     System.out.println(ArrayUtils.class.getDeclaredMethod("findMax", double[].class,int.class,int.class));
		} catch (Exception e1) {
		}
		
	}

}
